package minglu{
	import flash.net.FileReference;
	import morn.core.handlers.Handler;
	import utils.ChineseConvert;
	import utils.StringUtil;
	/**
	 * 远征军产生名录
	 * @author SXL
	 */
	public class MingLu{
		
		public function MingLu(){
			App.loader.loadTXT("nameList.txt",new Handler(this.readTxt));
		}
		private function readTxt(info:String):void{
			//trace(data);
			var users:Array=[];
			var data:Array=info.split("\n");
			
			/*
			//中文产生
			for(var i:int=0;i<data.length;i++){
				data[i]=data[i].split("\t");
			}
			
			for(i=0;i<data.length;i++){
				users.push(this.creatUser(data[i]));
			}
			/*/
			//英文产生
			var str:String;
			for(var i:int=0;i<data.length;i++){
				var user:Object={};
				str=StringUtil.trim(data[i]);
				var arr:Array;
				if(str.indexOf(".")!=-1){
					arr=data[i].split(".");
				}else{
					arr=data[i].split(" ");
				}
				str="";
				for(var j:int=0;j<arr.length;j++){
					arr[j]=StringUtil.trim(arr[j]);
					if(arr[j]=="") continue;
					str=str+arr[j].substr(0,1).toLowerCase();
					user["f" + (j+1)] =str;
				}
				user.info=data[i];
				users.push(user);
			}
			//*/
			var fileReference:FileReference=new FileReference();
			fileReference.save(JSON.stringify(users),"tab.txt");
			//trace(JSON.stringify(users));
		}
		private function creatUser(data:Array):Object{
			var name:String=data[0];
			var user:Object={};
			for (var i:int = 1; i <= name.length; i++) {
				user["f" + i] = ChineseConvert.convertString(name.substr(0, i));
			}
			user.info=data.join(" ");
			return user;
		}
	}
}